/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mygame.GUI;

import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import mygame.Backbone.GlobalVars;
import mygame.Manager;

/**
 *
 * @author Tobi
 */
public class MenuHandler implements ActionListener{

    private InputManager ipm;
    private GUIManager guim;
    
    public MenuHandler(InputManager ipm,GUIManager guim){
        this.ipm = ipm;
        this.guim = guim;
    }
    
    public void onAction(String name, boolean isPressed, float tpf) {
        if(name.equals(GlobalVars.ACTION_ESC) && !isPressed){
            guim.removeNiftyGUI();
            Manager.GetInstance().setupGameKeys();
            Manager.GetInstance().setGameMode(GlobalVars.GAME_MODE_PLAYING);
            guim.init();
            guim.setInMenu(false);
        }
    }
    
    public void resumeToGame(){
        ipm.clearMappings();
        Manager.GetInstance().setGameMode(GlobalVars.GAME_MODE_PLAYING);
    }
    
    public void setupGameKeys() {
        ipm.addMapping(GlobalVars.ACTION_ESC, new KeyTrigger(KeyInput.KEY_ESCAPE));
        String[] mapping = new String[]{
            GlobalVars.ACTION_ESC
        };
        //add listener to inputManager       
        ipm.addListener(this, mapping);
    }
}
